package com.evil.enterprise.controller;

import com.evil.application.api.RemoteApplicationProcessNodeService;
import com.evil.application.pojo.dto.form.control.ControlBaseInfoDTO;
import com.evil.common.account.dto.user.UserBaseRespDTO;
import com.evil.common.application.dto.order.node.OrderNodeReqDTO;
import com.evil.common.application.dto.process.DynamicHandlerControlListReqDTO;
import com.evil.common.application.dto.process.node.AddNodeReqDTO;
import com.evil.common.application.dto.process.node.ModifyNodeInfoReqDTO;
import com.evil.common.application.dto.process.node.NodeBaseDTO;
import com.evil.common.application.dto.process.node.NodeRespInfoDTO;
import com.evil.common.core.entity.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 应用流程接口
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/application/process/node")
public class ApplicationProcessNodeController {

    private final RemoteApplicationProcessNodeService remoteApplicationProcessNodeService;

    /**
     * 添加应用流程节点
     *
     * @param addNodeReqDTO addNodeReqDTO
     * @return R
     */
    @PostMapping("/add")
    public R<NodeRespInfoDTO> addApplicationProcessNode(@Validated @RequestBody AddNodeReqDTO addNodeReqDTO) {
        return R.success(remoteApplicationProcessNodeService.addApplicationProcessNode(addNodeReqDTO));
    }

    /**
     * 删除应用流程节点
     *
     * @param nodeId nodeId
     * @return R
     */
    @PostMapping("/delete")
    public R<?> deleteApplicationProcessNode(@RequestParam("nodeId") Long nodeId) {
        remoteApplicationProcessNodeService.deleteApplicationProcessNode(nodeId);
        return R.success();
    }

    /**
     * 编辑应用流程节点
     *
     * @param modifyNodeReqDTO modifyNodeReqDTO
     * @return R
     */
    @PostMapping("/modify")
    public R<?> modifyApplicationProcessNode(@Validated @RequestBody ModifyNodeInfoReqDTO modifyNodeReqDTO) {
        remoteApplicationProcessNodeService.modifyApplicationProcessNode(modifyNodeReqDTO);
        return R.success();
    }

    /**
     * 获取流程节点 可配置回退节点列表
     *
     * @param nodeId nodeId
     * @return R
     */
    @PostMapping("/can-setting-fallbacks")
    public R<List<NodeBaseDTO>> canSettingFallbacks(@RequestParam("nodeId") Long nodeId) {
        return R.success(remoteApplicationProcessNodeService.canSettingFallbacks(nodeId));
    }

    /**
     * 获取流程节点 可回退节点列表
     *
     * @param orderNodeReqDTO orderNodeReqDTO
     * @return R
     */
    @PostMapping("/can-fallbacks")
    public R<List<NodeBaseDTO>> canFallbacks(@Validated @RequestBody OrderNodeReqDTO orderNodeReqDTO) {
        return R.success(remoteApplicationProcessNodeService.canFallbacks(orderNodeReqDTO));
    }

    /**
     * 获取流程节点 可转交人员列表
     *
     * @param nodeId nodeId
     * @return R
     */
    @PostMapping("/can-reassignment")
    public R<List<UserBaseRespDTO>> canReassignment(@RequestParam("nodeId") Long nodeId) {
        return R.success(remoteApplicationProcessNodeService.canReassignment(nodeId));
    }

    /**
     * 获取流程节点 获取动态处理人对应权限控件列表
     *
     * @param dynamicHandlerControlListReqDTO dynamicHandlerControlListReqDTO
     * @return R
     */
    @PostMapping("/dynamic-handler-controls")
    public R<List<ControlBaseInfoDTO>> getDynamicHandlerControls(@Validated @RequestBody DynamicHandlerControlListReqDTO dynamicHandlerControlListReqDTO) {
        return R.success(remoteApplicationProcessNodeService.getDynamicHandlerControls(dynamicHandlerControlListReqDTO));
    }
}
